﻿<UserControl 
    Name="ObjectsPanel"
    x:Class="ObjectsPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:WPFZ80MapEditor"
    xmlns:converters="clr-namespace:WPFZ80MapEditor.ValueConverters"
    mc:Ignorable="d" 
    d:DesignHeight="232" d:DesignWidth="200" xmlns:my="clr-namespace:WPFZ80MapEditor">

    <UserControl.Resources>
        <converters:XImageConverter x:Key="ImageConverter"/>
        
        <Style x:Key="BorderStyle" TargetType="Border">
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderBrush">
                        <Setter.Value>
                            <SolidColorBrush Color="Gray"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid >
        
        <TabControl Name="ObjectsTabControl">
            <TabItem Header="Objects" Name="TilesTab" Tag="{x:Static local:LayerType.ObjectLayer}">
                <ScrollViewer Margin="0,0,0,0" VerticalScrollBarVisibility="Auto">
                    <StackPanel Orientation="Vertical">
                        <ItemsControl Grid.Row="0" ItemsSource="{Binding Path=Scenario.ObjectDefs.Values}" Name="ObjProperties" IsTabStop="False" Padding="0,0,0,0" 
                          Background="#FFF9F9F9">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical" Margin="0"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate DataType="{x:Type local:ZDef}">
                                    <Border Name="Border" BorderThickness="1" Background="#FFF9F9F9" Margin="3,0" Style="{StaticResource BorderStyle}">
                                        <StackPanel Name="ObjectContainer" Orientation="Horizontal" Height="20" VerticalAlignment="Center" SnapsToDevicePixels="True" 
                                            MouseMove="Object_MouseMove" 
                                            MouseLeftButtonUp="Object_MouseUp"
                                            GiveFeedback="Object_GiveFeedback"
                                            Background="#FFF9F9F9"
                                            >
                                            <StackPanel.Triggers>
                                            </StackPanel.Triggers>
                                            <Image Stretch="None" Width="40" x:Name="ObjectImage" UseLayoutRounding="True">
                                                <Image.Source>
                                                    <MultiBinding Converter="{StaticResource ImageConverter}">
                                                        <Binding Path="DataContext.Scenario" ElementName="ObjectsPanel"/>
                                                        <Binding Path="DefaultImage"/>
                                                    </MultiBinding>
                                                </Image.Source>
                                            </Image>
                                            <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Name="TextBlock1"/>
                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Enemies" Tag="{x:Static local:LayerType.EnemyLayer}">
                <ScrollViewer VerticalScrollBarVisibility="Auto">
                    <ItemsControl Grid.Row="0" ItemsSource="{Binding Path=Scenario.EnemyDefs.Values}" IsTabStop="False" Padding="0,0,0,0" 
                          Background="#FFF9F9F9">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" Margin="0"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="{x:Type local:ZDef}">
                                <Border Name="Border" BorderThickness="1" Background="#FFF9F9F9" Margin="3,0" Style="{StaticResource BorderStyle}">
                                    <StackPanel Name="ObjectContainer" Orientation="Horizontal" Height="20" VerticalAlignment="Center" SnapsToDevicePixels="True"  MouseMove="Object_MouseMove">
                                        <StackPanel.Triggers>
                                        </StackPanel.Triggers>
                                        <Image Stretch="None" Width="40" x:Name="ObjectImage" UseLayoutRounding="True">
                                            <Image.Source>
                                                <MultiBinding Converter="{StaticResource ImageConverter}">
                                                    <Binding Path="DataContext.Scenario" ElementName="ObjectsPanel"/>
                                                    <Binding Path="DefaultImage"/>
                                                </MultiBinding>
                                            </Image.Source>
                                        </Image>
                                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Misc" Tag="{x:Static local:LayerType.MiscLayer}">
                <ScrollViewer Margin="0,0,0,0" VerticalScrollBarVisibility="Auto">
                    <StackPanel Orientation="Vertical">
                        <ItemsControl Grid.Row="0" ItemsSource="{Binding Path=Scenario.MiscDefs.Values}" IsTabStop="False" Padding="0,0,0,0" 
                          Background="#FFF9F9F9">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical" Margin="0"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center" SnapsToDevicePixels="True" MouseMove="Object_MouseMove">
                                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Name="TextBlock1"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Scripts">
                <ScrollViewer Margin="0,0,0,0" VerticalScrollBarVisibility="Auto">
                    <StackPanel Orientation="Vertical">
                        <Label>Map-specific</Label>
                        <ListBox Grid.Row="0" ItemsSource="{Binding Path=SelectedMap.ZScript}" IsTabStop="False" Padding="0,0,0,0" 
                          Background="#FFF9F9F9">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center" SnapsToDevicePixels="True" MouseLeftButtonDown="Script_MouseLeftButtonDown">
                                        <TextBlock Text="{Binding Path=Args[1].Value}" VerticalAlignment="Center" Name="TextBlock1"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ListBox>
                        <Label>Built-in</Label>
                        <ItemsControl Grid.Row="0" ItemsSource="{Binding Path=Scenario.BuiltinScripts.Keys}" IsTabStop="False" Padding="0,0,0,0" 
                          Background="#FFF9F9F9">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical" Margin="0"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center" SnapsToDevicePixels="True" MouseLeftButtonDown="Script_MouseLeftButtonDown">
                                        <TextBlock Text="{Binding Path=.}" VerticalAlignment="Center" Name="TextBlock1"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>
